﻿using System;

namespace NMA.Infrastructure.NHibernate.DomainObject
{
    using NMA.Domain.Shared;
    using NMA.Infrastructure.DBC;
    using NMA.Domain.Model;

    public class News : BaseEntity<INews>, INews
    {
        public virtual string Title { get; set; }

        public virtual string ShortDescription { get; set; }

        public virtual string Content { get; set; }

        public virtual bool IsPublish { get; set; }

        public virtual DateTime PublishedDate { get; set; }

        public virtual string PublishedPerson { get; set; }

        public virtual int NumberOfView { get; set; }

        public virtual byte[] Image { get; set; }

        public virtual ICategory Category { get; set; }

        public virtual IPoll Poll { get; set; }

        public virtual string CreatedUser { get; set; }

        public virtual string UpdatedUser { get; set; }        

        public News()
        {
            // need it for NHibernate
        }

        public virtual void AssignPoll(IPoll poll)
        {
            //poll.News = this;
            Poll = poll;
        }

        public virtual void AssignCategory(ICategory cat)
        {
            cat.News.Add(this);
            Category = cat;
        }

        public override bool SameIdentityAs(INews other)
        {
            Check.Assert(other == null, "News is null");

            return other.Id == this.Id;
        }
    }
}
